package com.wude.guild.manager;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.wude.http.NetWorkBroadcast;


/**
 * 监听网络变化Service
 * Created by Administrator on 2017/3/15.
 */

public class NetworkService extends Service {

    private NetWorkBroadcast netWorkBroadcast;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if(netWorkBroadcast==null){
            netWorkBroadcast = new NetWorkBroadcast();
            IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
            registerReceiver(netWorkBroadcast,filter);
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(netWorkBroadcast!=null){
            unregisterReceiver(netWorkBroadcast);
        }
    }
}
